<template>
  <div class="categroyes">
      <el-button plain type="success">添加商品分类</el-button>
      <!-- 商品表格区域 -->
       <el-table
        :data="productList"
        :default-sort = "{prop: 'cat_id', order: 'descending'}"
        height="400"
        row-key="cat_id"
        style="width: 100%"
        >
        <!-- <el-table-column  label="#"  type="index" :index="filterIndex"></el-table-column> -->
        <el-table-column  prop="cat_id" label="商品编号"  sortable></el-table-column>
        <el-table-column prop="cat_name" label="分类名称"  width="180"></el-table-column>
        <el-table-column label="是否有效"  width="180">
            <template v-slot:default="{row}">
                {{row.cat_deleted==false?"是":"否"}}
            </template>
         </el-table-column>
        <el-table-column  label="层级">
            <template v-slot:default="{row}">
                {{row.cat_level==0?"一级":"二级"}}
            </template>
        </el-table-column>
        <el-table-column   label="操作" width="180">
            <template v-slot:default="{row}">
				<el-button  type="primary" size="small" plain icon="el-icon-edit"></el-button>
				<el-button type="danger" size="small" icon="el-icon-delete" plain></el-button>
            </template>
        </el-table-column>
    </el-table>
    <!-- 分页器 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :page-sizes="[5, 8, 10, 12]"
      :page-size="5"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
 
  </div>
</template>

<script>
export default {
    data(){
        return{
            total:44,
            pagenum:1,
            pagesize:5,
            productList:[],
            leval2:[],
        }
    },
    created(){
        this.getProductList();
    },
    methods:{
        async getProductList(){
            const res=await this.$axios.get("categories",{
                params:{
                    type:3,
                    pagenum:this.pagenum,
                    pagesize:this.pagesize,
                }
            })
            if(res.data.meta.status==200){
                this.productList=res.data.data.result;
                this.productList.forEach(item=>{
                    this.leval2=item.children;
                });
                this.total=res.data.data.total;
                // console.log(this.productList);
                console.log(this.productList)
            }
        },
        handleSizeChange(val) {
            this.pagesize=val;
            this.getProductList();
        },
        handleCurrentChange(val) {
            this.pagenum=val;
            this.getProductList();
        },
        // 页码标签处理函数
		filterIndex(index){
			return index+1+this.pagesize*(this.pagenum-1)
		}   
    }
 
}
</script>

<style>

</style>